home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / utils / Variables.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.9 KB  |  163 lines

  1. package com.google.analytics.utils
  2. {
  3.    import flash.net.URLVariables;
  4.    
  5.    public dynamic class Variables
  6.    {
  7.        
  8.       
  9.       public var post:Array;
  10.       
  11.       public var URIencode:Boolean;
  12.       
  13.       public var pre:Array;
  14.       
  15.       public var sort:Boolean = true;
  16.       
  17.       public function Variables(source:String = null, pre:Array = null, post:Array = null)
  18.       {
  19.          pre = [];
  20.          post = [];
  21.          super();
  22.          if(source)
  23.          {
  24.             decode(source);
  25.          }
  26.          if(pre)
  27.          {
  28.             this.pre = pre;
  29.          }
  30.          if(post)
  31.          {
  32.             this.post = post;
  33.          }
  34.       }
  35.       
  36.       private function _join(vars:Variables) : void
  37.       {
  38.          var prop:String = null;
  39.          if(!vars)
  40.          {
  41.             return;
  42.          }
  43.          for(prop in vars)
  44.          {
  45.             this[prop] = vars[prop];
  46.          }
  47.       }
  48.       
  49.       public function join(... variables) : void
  50.       {
  51.          var l:int = int(variables.length);
  52.          for(var i:int = 0; i < l; i++)
  53.          {
  54.             if(variables[i] is Variables)
  55.             {
  56.                _join(variables[i]);
  57.             }
  58.          }
  59.       }
  60.       
  61.       public function toString() : String
  62.       {
  63.          var value:String = null;
  64.          var p:String = null;
  65.          var component:String = null;
  66.          var i:int = 0;
  67.          var j:int = 0;
  68.          var priority:String = null;
  69.          var last:String = null;
  70.          var data:Array = [];
  71.          for(p in this)
  72.          {
  73.             value = String(this[p]);
  74.             if(URIencode)
  75.             {
  76.                value = encodeURI(value);
  77.             }
  78.             data.push(p + "=" + value);
  79.          }
  80.          if(sort)
  81.          {
  82.             data.sort();
  83.          }
  84.          if(pre.length > 0)
  85.          {
  86.             pre.reverse();
  87.             for(i = 0; i < pre.length; i++)
  88.             {
  89.                priority = String(pre[i]);
  90.                for(j = 0; j < data.length; j++)
  91.                {
  92.                   component = String(data[j]);
  93.                   if(component.indexOf(priority) == 0)
  94.                   {
  95.                      data.unshift(data.splice(j,1)[0]);
  96.                   }
  97.                }
  98.             }
  99.             pre.reverse();
  100.          }
  101.          if(post.length > 0)
  102.          {
  103.             for(i = 0; i < post.length; i++)
  104.             {
  105.                last = String(post[i]);
  106.                for(j = 0; j < data.length; j++)
  107.                {
  108.                   component = String(data[j]);
  109.                   if(component.indexOf(last) == 0)
  110.                   {
  111.                      data.push(data.splice(j,1)[0]);
  112.                   }
  113.                }
  114.             }
  115.          }
  116.          return data.join("&");
  117.       }
  118.       
  119.       public function decode(source:String) : void
  120.       {
  121.          var data:Array = null;
  122.          var prop:String = null;
  123.          var name:String = null;
  124.          var value:String = null;
  125.          var tmp:Array = null;
  126.          if(source == "")
  127.          {
  128.             return;
  129.          }
  130.          if(source.indexOf("&") > -1)
  131.          {
  132.             data = source.split("&");
  133.          }
  134.          else
  135.          {
  136.             data = [source];
  137.          }
  138.          for(var i:int = 0; i < data.length; i++)
  139.          {
  140.             prop = String(data[i]);
  141.             if(prop.indexOf("=") > -1)
  142.             {
  143.                tmp = prop.split("=");
  144.                name = String(tmp[0]);
  145.                value = decodeURI(tmp[1]);
  146.                this[name] = value;
  147.             }
  148.          }
  149.       }
  150.       
  151.       public function toURLVariables() : URLVariables
  152.       {
  153.          var p:String = null;
  154.          var urlvars:URLVariables = new URLVariables();
  155.          for(p in this)
  156.          {
  157.             urlvars[p] = this[p];
  158.          }
  159.          return urlvars;
  160.       }
  161.    }
  162. }
  163.